package com.pc.controller;

import com.pc.entity.Changemoney;
import com.pc.service.ChangemoneyService;

import com.pc.utils.Result;
import com.pc.utils.aop.OperLog;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("changemoney")
public class ChangemoneyController {
    @Resource
    private ChangemoneyService changemoneyService;

    //充值记录
    @PostMapping("getUserAddMoney")
    @OperLog(operModul = "充值模块",operType = "增加",operDesc = "注册用户时,送用户3000元")
    public Result getUserAddMoney(@RequestBody Object obj){
        Map entity = (Map)obj;
        String username = entity.get("username").toString();
        String addmoney = entity.get("addmoney").toString();
        Integer value = Integer.valueOf(addmoney);
        boolean b = changemoneyService.addChange(username, value);
        if(b)
            return Result.success("记录插入成功",true);
        else
            return Result.fail("记录充值失败",false);
    }

    //得到充值记录
    @GetMapping("getChangeMoney/{username}")
    @OperLog(operModul = "充值模块",operType = "查询",operDesc = "查询用户充值记录")
    public Result getChangeMoney(@PathVariable String username){
        List<Changemoney> order = changemoneyService.getOrder(username);
        if(order.size()>0)
            return Result.success("获取成功",order);
        else
            return Result.fail("获取失败");
    }
}
